package cn.com.xuhx.testMapper;

import cn.com.xuhx.mapper.UpdateMapper;
import cn.com.xuhx.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.Date;

/**
 * 修改SQL
 */
public class UpdateTest {

    private SqlSession sqlSession = null;

    @Before
    public void getSQLSession() throws IOException {
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(resourceAsStream);
        //设置需要手动提交事务
        //sqlSession = build.openSession();
        //设置自动提交事务
        sqlSession = build.openSession(true);
    }

    @After
    public void closeSQLSession(){
        sqlSession.clearCache();
        sqlSession.close();
    }

    /**
     * 修改
     */
    @Test
    public void testUpdate(){
        UpdateMapper mapper = sqlSession.getMapper(UpdateMapper.class);
        User user = new User(1,"李四", 24, "江苏省", "18115188222", "320672199110011085", new Date());
        mapper.updateUser(user);
    }
}
